#include<bits/stdc++.h>
#define int long long 
#define fir first
#define sec second 
#define mk make_pair
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x);write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=8e5+5;
int n,ans;
struct node{
	int u,v,c,id;
}e[N];
int fa[N],siz[N],p[N];
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
vector<pair<int,int>>to[N];
int f[N][25],g[N][25];
void Init(){
	sort(e+1,e+n,[](node A,node B){return A.c>B.c;});
	for(int i=1;i<=n;i++)fa[i]=i,siz[i]=1;
	for(int i=1;i<n;i++){
		int X=find(e[i].u),Y=find(e[i].v);
		ans+=1ll*e[i].c*siz[X]*siz[Y];
		fa[X]=Y,siz[Y]+=siz[X];
	}
	sort(e+1,e+n,[](node A,node B){return A.id<B.id;});
}
void dfs1(int x,int F){
	fa[x]=F;
	if(x!=1)to[x].erase(lower_bound(to[x].begin(),to[x].end(),mk(fa[x],p[x])));
	f[x][20]++;
	for(auto E:to[x]){
		int y=E.fir,w=E.sec;
		p[y]=w;
		dfs1(y,x);
		for(int i=0;i<=20;i++)
			f[x][i]+=f[y][i];
	}
	for(int i=p[x]+1;i<=20;i++)
		f[x][p[x]]+=f[x][i],
		f[x][i]=0;
}
int now[25],pre[N][25],suf[N][25];
void dfs2(int x){
	for(int i=0;i<=20;i++)now[i]=g[x][i];
	for(int i=p[x]+1;i<=20;i++)now[p[x]]+=now[i],now[i]=0;
	now[20]++;
	for(int i=0;i<to[x].size();i++){
		int y=to[x][i].first;
		for(int j=0;j<=20;j++)
			pre[i][j]=f[y][j];
		if(i)for(int j=0;j<=20;j++)pre[i][j]+=pre[i-1][j];
	}
	for(int i=to[x].size()-1;i>=0;i--){
		int y=to[x][i].first;
		for(int j=0;j<=20;j++)
			suf[i][j]=f[y][j];
		if(i+1<to[x].size())for(int j=0;j<=20;j++)suf[i][j]+=suf[i+1][j];
	}
	for(int i=0;i<to[x].size();i++){
		int y=to[x][i].fir;
		for(int j=0;j<=20;j++)g[y][j]+=now[j];
		if(i)for(int j=0;j<=20;j++)g[y][j]+=pre[i-1][j];
		if(i+1<to[x].size())for(int j=0;j<=20;j++)g[y][j]+=suf[i+1][j];
	}
	for(int i=0;i<to[x].size();i++)
		dfs2(to[x][i].first);
}
signed main(){
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	read(n);
	for(int i=1;i<n;i++)read(e[i].u,e[i].v,e[i].c),e[i].id=i;
	for(int i=1;i<n;i++)
		to[e[i].u].push_back(mk(e[i].v,e[i].c)),
		to[e[i].v].push_back(mk(e[i].u,e[i].c));
	for(int i=1;i<=n;i++)sort(to[i].begin(),to[i].end());
	Init();
	dfs1(1,0);
	dfs2(1);
//	for(int i=1;i<=n;i++){
//		cout<<i<<'/'<<p[i]<<":\n";
//		for(int j=0;j<=20;j++)cout<<f[i][j]<<' ';cout<<'\n';
//		for(int j=0;j<=20;j++)cout<<g[i][j]<<' ';cout<<'\n';	
//	}
	for(int i=1;i<n;i++){
		if(fa[e[i].v]!=e[i].u)swap(e[i].v,e[i].u);
		int sum=0,cnt=0;
		for(int j=20;j>=1;j--){
			cnt+=g[e[i].v][j];
			sum+=j*f[e[i].v][j]*cnt;
		}
		cnt=0;
		for(int j=20;j>=1;j--){
			sum+=j*g[e[i].v][j]*cnt;
			cnt+=f[e[i].v][j];	
		}
		write(ans-sum),putch('\n');
	}
	flush();
	return 0;
}/*
4
2 1 10
3 1 1
4 1 5

*/
